package com.southminority.ethnic.controller.admin.category;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.southminority.ethnic.common.result.R;
import com.southminority.ethnic.mapper.category.CategoryMapper;
import com.southminority.ethnic.pojo.Category;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@Tag(name = "分类管理", description = "通用分类列表接口")
@RequestMapping("/admin/category")
public class CategoryAdminController {

    private final CategoryMapper categoryMapper;

    public CategoryAdminController(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @GetMapping("/list")
    @Operation(summary = "获取启用的分类列表", description = "返回 status=1 的分类，按 sort_order 升序")
    public R<List<Category>> list() {
        QueryWrapper<Category> qw = new QueryWrapper<>();
        qw.eq("status", 1).orderByAsc("sort_order").orderByAsc("id");
        List<Category> list = categoryMapper.selectList(qw);
        return R.ok(list);
    }
}


